SELECT ORG_UNIT."ID", ORG_UNIT."NAME",ORG_UNIT.CODE,CASE WHEN OU.CODE = 'company' THEN NULL ELSE OU.CODE END AS parentcode FROM ORG_UNIT
LEFT JOIN ORG_UNIT ou ON ou."PATH" = "SUBSTR"(ORG_UNIT."PATH",0,"LENGTH"(ORG_UNIT."PATH")-4) AND ou.IS_DELETED = 0 AND ou.IS_ENABLE = 1 
WHERE ORG_UNIT.IS_DELETED = 0 AND ORG_UNIT.IS_ENABLE = 1 AND "LENGTH"(ORG_UNIT."PATH") > 8
ORDER BY ORG_UNIT.CODE